package com.xxxx.blog.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.blog.entity.FriendLink;
import com.xxxx.blog.mapper.FriendLinkMapper;
import com.xxxx.blog.service.FriendLinkService;
import com.xxxx.blog.utils.Maps;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class FriendLinkServiceImpl extends ServiceImpl<FriendLinkMapper,FriendLink> implements FriendLinkService {

    private final FriendLinkMapper friendLinkMapper;

    public int create(FriendLink friendLink){
        return friendLinkMapper.create(friendLink);
    }

    public int delete(Integer id){
        return friendLinkMapper.delete(Maps.build(id).getMap());
    }

    public int update(FriendLink friendLink){
        return friendLinkMapper.update(Maps.build(friendLink.getId()).beanToMapForUpdate(friendLink));
    }

    public PageInfo<FriendLink> query(FriendLink friendLink){
        if(friendLink != null && friendLink.getPage() != null){
            PageHelper.startPage(friendLink.getPage(),friendLink.getLimit());
        }
        List<FriendLink> list = friendLinkMapper.query(Maps.build().beanToMap(friendLink));
        return new PageInfo<FriendLink>(list);
    }

    public FriendLink detail(Integer id){
        return friendLinkMapper.detail(Maps.build(id).getMap());
    }

    public int count(FriendLink friendLink){
        return friendLinkMapper.count(Maps.build().beanToMap(friendLink));
    }


}
